package org.example.utils.user;

import org.example.dao.dto.user.CalenderDto;
import org.example.skytool.json.JackSonUtil;
import org.example.skytool.redis.RedisUtils;
import org.joda.time.Days;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.example.skytool.redis.RedisConstants.*;

/**
 * @author 22449
 */
@Component
public class RedisJwService {

    @Resource
    private RedisUtils redisUtils;

    private String getSemesterTotalKey(String year) {
        String key = JW_MOUDLE + JW_DATA_CONTROLLER + JW_DATA_SEMESTER_KIND + JW_DATA_SEMESTER_ALL_KIND + year;
        return key;
    }

    private String getSemesterNowKey() {
        String key = JW_MOUDLE + JW_DATA_CONTROLLER + JW_DATA_SEMESTER_KIND + JW_DATA_SEMESTER_NOW_KIND;
        return key;
    }

    private String getWeekNowKey() {
        String key = JW_MOUDLE + JW_DATA_CONTROLLER + JW_DATA_WEEK_KIND + JW_DATA_WEEK_NOW_KIND;
        return key;
    }

    private String getWeekInfoKey(String weekData) {
        String key = JW_MOUDLE + JW_DATA_CONTROLLER + JW_DATA_WEEK_KIND + JW_DATA_WEEK_INFO_KIND + weekData;
        return key;
    }

    public void setSemesterTotal(String year, List<String> list) {
        redisUtils.objectSet(getSemesterTotalKey(year), list, 1L, TimeUnit.DAYS);
    }

    public List<String> getSemesterTotal(String year) {
        return redisUtils.objectGet(getSemesterTotalKey(year), List.class);
    }

    public void setSemesterNow(String semesterNow) {
        redisUtils.stringSet(getSemesterNowKey(), semesterNow, 1L, TimeUnit.DAYS);
    }

    public String getSemesterNow() {
        return redisUtils.stringGet(getSemesterNowKey());
    }

    public void setWeekNow(String weekNow) {
        redisUtils.stringSet(getWeekNowKey(), weekNow, 1L, TimeUnit.DAYS);
    }

    public String getWeekNow() {
        return redisUtils.stringGet(getWeekNowKey());
    }

    public void setWeekInfo(String week, List<CalenderDto> list) {
        redisUtils.objectSet(getWeekInfoKey(week), list, 1L, TimeUnit.DAYS);
    }

    public List<CalenderDto> getWeekInfo(String week) {
        return redisUtils.objectGet(getWeekInfoKey(week), List.class);
    }


}
